import tkinter as tk
from tkinter import filedialog
import cv2
from PIL import Image, ImageTk
def open_file():
    file_path = filedialog.askopenfilename(title="Select Video", filetypes=(("Video files", "*.mp4;*.avi"),))
    if file_path:
        play_video(file_path)

def play_video(file_path):
    cap = cv2.VideoCapture(file_path)
    while True:
        ret, frame = cap.read()
        if not ret:
            break
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        img = Image.fromarray(frame)
        img = ImageTk.PhotoImage(image=img)
        video_label.imgtk = img
        video_label.configure(image=img)
        video_label.update()
    cap.release()

root = tk.Tk()
root.title("Video Player")
root.geometry("640x480")

video_label = tk.Label(root)
video_label.pack()

open_button = tk.Button(root, text="Open Video", command=open_file)
open_button.pack()

root.mainloop()